package com.onpositive.wikitemplate;

import java.util.HashMap;

public class DefaultNoParamsTemplateResolver extends AbstractNoParamsTemplateResolver {
	
	private static DefaultNoParamsTemplateResolver instance ;
	
	public static DefaultNoParamsTemplateResolver getinstance(){
		if(instance == null)
			instance = new DefaultNoParamsTemplateResolver() ;
		
		return instance ;
	}
	
	private static HashMap<String,String> redirects = new HashMap<String, String>() ;
	{
		redirects.put( "US".toLowerCase(), "USA" ) ;
		redirects.put( "UK".toLowerCase(), "GBR" ) ;
		redirects.put( "USSR".toLowerCase(), "URS" ) ;
		redirects.put( "ROK".toLowerCase(), "KOR" ) ;//Korea
		redirects.put( "NZ".toLowerCase(), "NZL" ) ;//New Zeland, redirect
		redirects.put( "JAP".toLowerCase(), "JPN" ) ;//Japan, redirect
		redirects.put( "ROM".toLowerCase(), "ROU" ) ;//Romania, redirect
	}
	
	private static HashMap<String,String> specialResolvings = new HashMap<String, String>() ;
	{
		redirects.put( "PRC".toLowerCase(), "People's Republic of China" ) ;//China
	}
	
	@Override	
	public String resolve(String templateName) {
		
		String result = null ;
		result = MarksTemplateResolver.getInstance().resolve(templateName) ;
		if(result != null)
			return result ;
		
		String str = redirects.get(templateName.toLowerCase()) ;
		if( str != null )
			templateName = str ;
		
		if( templateName.length() != 3 || !templateName.toUpperCase().equals(templateName) )
			return null ;
			
		String resolvedString = null;
		CountryInfo_ISO_3166_1_alpha_3.CountryInfo info1 = 
				CountryInfo_ISO_3166_1_alpha_3.getInstance().getCountryInfo(templateName) ;
			
		if( info1 != null )
			resolvedString  = info1.getWikiLink();
				
		if( resolvedString == null ){			
			FIFA_Country_Codes.CountryInfo info2 = 
					FIFA_Country_Codes.getInstance().getCountryInfo(templateName) ;
			
			if( info2 != null )
				resolvedString  = info2.getWikiLink();
		}
			
		if( resolvedString == null )
			resolvedString = specialResolvings.get( templateName.toLowerCase() ) ;
			
		if( resolvedString == null )
			return null ;
			
		result = "[[" + resolvedString + "]]" ;
		return result ;
	}

}
